/**
 * 
 * @author Sunix
 * @date   2013-5-17
 * @Email  SunixSky@gmail.com
 * 
 * 文件浏览工具条
 * 
 */	
package view.components{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filesystem.File;
	
	import manager.LoggerManager;
	import manager.ShareDataManager;
	
	import scaleform.clik.controls.Button;
	import scaleform.clik.controls.TextInput;

	public class FileBrowse extends Sprite{
			
		public var browse:Button;  //浏览按钮	
		public var filePath:TextInput;  //文件路径	
		public var file:File;  //文件对象
		public var key:String;  //共享数据键
		
		public function FileBrowse(){
			file = new File();
			addEventListener(Event.ADDED_TO_STAGE,onAddedToStage);
		}
		
		protected function onAddedToStage(event:Event):void{
			browse.addEventListener(MouseEvent.CLICK,onClick);
			var value:String = ShareDataManager.getSOValue(key);
			if(value){
				filePath.text = value;
				file.nativePath = value;
			}
		}
		
		protected function onClick(event:MouseEvent):void{
			file.browseForDirectory("请选择路径");	
			file.addEventListener(Event.SELECT, this.onSelected);
		}	
		
		protected function onSelected(event:Event):void{
			var path:String = event.target.nativePath;
			filePath.text = path;
			ShareDataManager.addSOValue(key,path);
			LoggerManager.log("已选择路径：",path);
		}
	}
}